// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.utils;

public final class UpdateLimit {
    private long delay;
    private long last;
    private long lastPeriod;

    public UpdateLimit(long ms) {
        this.delay = ms;
        this.last = System.currentTimeMillis();
        this.lastPeriod = this.last;
    }

    public UpdateLimit(long ms, long shift) {
        this.delay = ms;
        this.last = System.currentTimeMillis() - shift;
        this.lastPeriod = this.last;
    }

    public void BlockCheck() {
        this.last = System.currentTimeMillis() + this.delay;
    }

    public void Reset(long ms) {
        this.delay = ms;
        this.Reset();
    }

    public void Reset() {
        this.last = System.currentTimeMillis();
        this.lastPeriod = System.currentTimeMillis();
    }

    public void setUpdatePeriod(long ms) {
        this.delay = ms;
    }

    public void setSmoothUpdatePeriod(long ms) {
        this.delay = (long)((float)this.delay + 0.1F * (float)(ms - this.delay));
    }

    public boolean Check() {
        long _long = System.currentTimeMillis();
        if (_long - this.last > this.delay) {
            if (_long - this.last > 3L * this.delay) {
                this.last = _long;
            } else {
                this.last = this.last + this.delay;
            }

            return true;
        } else {
            return false;
        }
    }

    public long getLast() {
        return this.last;
    }

    public void updateTimePeriod() {
        long _long = System.currentTimeMillis();
        if (_long - this.last > this.delay) {
            if (_long - this.last > 3L * this.delay) {
                this.last = _long;
            } else {
                this.last = this.last + this.delay;
            }
        }

        this.lastPeriod = _long;
    }

    public double getTimePeriod() {
        return Math.min(((double)System.currentTimeMillis() - (double)this.lastPeriod) / (double)this.delay, 1.0);
    }

    public long getDelay() {
        return this.delay;
    }
}
